package backend;

import java.util.List;

public class Product implements Comparable<Product> {
	private int id;
	private int category_id;
	private int subcategory_id;
	private String name;
	private double sRank;
	private double price;
	private String image_url;
	private ProductInformation extraInformation;

	public Product(int id,int category_id, int subcategory_id, String name,double rank,
			double price, String image_url, ProductInformation extraInformation) {
		super();
		this.id = id;
		this.category_id=category_id;
		this.subcategory_id = subcategory_id;
		this.name = name;
		this.sRank = rank;
		this.price = price;
		this.image_url = image_url;
		this.extraInformation = extraInformation;
	}

        public String getName(){
            return name;
        }

        public double getRank(){
            return sRank;
        }

        public double getPrice(){
            return price;
        }

        public String getImage(){
            return image_url;
        }

        public String getCategory(){
            switch(category_id){
                case 1:
                        return "DVD";
                case 2:
                        return "Book";
            }
            return "Error";
        }

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + subcategory_id;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Product))
			return false;
		Product other = (Product) obj;
		if (id != other.id)
			return false;
		if (subcategory_id != other.subcategory_id)
			return false;
		return true;
	}

	public String toString(){
		return name+"-"+id+"-"+category_id+"-"+subcategory_id+"-"+sRank+"-"+price+"-"+image_url+"-"+extraInformation;
	}

	
	public boolean hasExtraInformation() {
		return extraInformation!=null;
	}

	/**
	 * @param extraInformation the extraInformation to set
	 */
	public void setExtraInformation(ProductInformation extraInformation) {
		this.extraInformation = extraInformation;
	}

	@Override
	public int compareTo(Product obj) {
		return this.name.compareTo(obj.name);
	}
	
	public List<String> getProductInformation() throws Exception{
		if(this.extraInformation==null){
			switch(this.category_id){
			case 1: this.extraInformation=new DvdInformation(this.id);
				break;
			case 2: this.extraInformation=new BookInformation(this.id);
				break;
				}
			}
		return this.extraInformation.getValues();
	}
}
